/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdMetadataDatabaseBo;
import com.comac.ins.isfd.domain.vo.IsfdMetadataDatabaseVo;
import com.comac.ins.isfd.service.IIsfdMetadataDatabaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 元数据管理-要素库
 *
 * @author Lion Li
 * @date 2024-09-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/metadataDatabase")
public class IsfdMetadataDatabaseController extends BaseController {

    @Autowired
    private IIsfdMetadataDatabaseService isfdMetadataDatabaseService;

    /**
     * 查询元数据管理-要素库列表
     */
    @SaCheckPermission("isfd:metadataDatabase:list")
    @GetMapping("/list")
    public TableDataInfo<IsfdMetadataDatabaseVo> list(IsfdMetadataDatabaseBo bo, PageQuery pageQuery) {
        return isfdMetadataDatabaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询符合条件的元数据管理-要素库列表
     */
    @SaCheckPermission("isfd:metadataDatabase:list")
    @GetMapping("/list/query")
    public TableDataInfo<IsfdMetadataDatabaseVo> queryList(IsfdMetadataDatabaseBo bo, PageQuery pageQuery) {
        return isfdMetadataDatabaseService.queryList(bo, pageQuery);
    }
    /**
     * 获取元数据管理-要素库详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:metadataDatabase:query")
    @GetMapping("/{id}")
    public R<IsfdMetadataDatabaseVo> getInfo(@NotNull(message = "主键不能为空")
                                             @PathVariable Long id) {
        return R.ok(isfdMetadataDatabaseService.queryById(id));
    }

    /**
     * 新增元数据管理-要素库
     */

    @SaCheckPermission("isfd:metadataDatabase:add")
    @PostMapping(value = "/add")
    @Operation(summary = "元素据管理-要素库新增", security = @SecurityRequirement(name = "isfd:metadataDatabase:add"))
    public R<Void> parameterConfigAnalysisAdd(@RequestBody IsfdMetadataDatabaseBo isfdMetadataDatabaseBo) {
        return toAjax(isfdMetadataDatabaseService.insertByBo(isfdMetadataDatabaseBo));
    }


    /**
     * 修改元数据管理-要素库
     */


    @SaCheckPermission("isfd:metadataDatabase:edit")
    @PostMapping(value = "/edit")
    @Operation(summary = "元素据管理修改", security = @SecurityRequirement(name = "isfd:metadataDatabase:edit"))
    public R<Void> edit(@RequestBody IsfdMetadataDatabaseBo bo) {
        return toAjax(isfdMetadataDatabaseService.updateByBo(bo));
    }
    /**
     * 删除元数据管理-要素库
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:metadataDatabase:remove")
    @Log(title = "元数据管理-要素库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdMetadataDatabaseService.deleteWithValidByIds(List.of(ids)));
    }
}
